(function ($) { //global var menuIsShowing = false; //menu is displayed after the whatson ajax callback has finished, call more results could trigger the menu to display again //FUNCTION to build the search menu function bfi_build_search_menu() { var menuItems = ''; //display anchor menu if (menuIsShowing == false) { //find all the anchors to build up a menu list $('h2.section-title').each(function() { var menuTitle = ''; var blockId = ''; totalResultsCount = 0; var $this = $(this); //get the block title menuTitle = $this.text(); //get the block id this block title sits in blockId = $this.attr('id'); //get the total number of results per section if available var $subsections = $this.siblings('.bfi-search-result-group').children('.bfi-more-search-results-info'); $subsections.each(function() { // add the total number of results per subsection totalResultsCount += parseInt($(this).children('.number-of-results').text()); }); //build up the menu list menuItems += Drupal.theme('bfiSearchMenuItem', blockId, menuTitle, totalResultsCount); }); //if there are some menu items then display them if (menuItems) { menuIsShowing = true; //menu has been shown, so any more ajax calls wont set it again $('div#search-results-menu').html(Drupal.theme('bfiSearchMenu', menuItems)); //bind a click event to each nav item $('.bfi-search-nav').bind('click', function() { var $this = $(this); //get this menu items block id which matches the block id to scroll to menuBlockId = $this.attr('data-block-id'); //scroll to the h2 id $.scrollTo('#' + menuBlockId, 800); }); } } } //THEME for anchor menu Drupal.theme.prototype.bfiSearchMenu = function(menuItems) { return '
'; } //THEME for anchor item Drupal.theme.prototype.bfiSearchMenuItem = function(blockId, menuTitle, totalResultsCount) { var resultsOutput = ''; if (totalResultsCount) { resultsOutput = ' (' + totalResultsCount + ')'; } return '
  • ' + menuTitle + resultsOutput + '
  • '; } //Document ready Drupal.behaviors.bfi_search = { attach: function (context, settings) { var isPageAjaxing = false; //to indicate if there's ajax requests on the page var ajaxingSearch = false; //to stop clicking if ajax in progress $('.bfi-search-result-group').removeClass('active'); //the default results have the active class so remove it //notify that some ajax has been triggered on the page when document is ready $(document).ajaxStart(function () { isPageAjaxing = true; }); //if there was some ajax the when its finished build the menu $(document).ajaxStop(function () { bfi_build_search_menu(); //if there's ajax then we need to wait to bind the back to top link $('.bfi-search-nav-top-inline').bind('click', function() { $.scrollTo('#page_top', 100); }); }); //once all the scripts have been loaded on the page (after document ready) $(window).load(function() { //if there was no ajax on the page then build the menu if (isPageAjaxing == false) { bfi_build_search_menu(); //if there's no ajax then we dont need to wait to bind the back to top link $('.bfi-search-nav-top-inline').bind('click', function() { $.scrollTo('#page_top', 100); }); } }); $('.bfi-more-search-results').bind('click', function() { //can't ajax if ajax is in progress if (!ajaxingSearch) { //get the current element var $currentElement = $(this); //get all the data attributes from the show more results action var startIndex = $currentElement.attr('data-start-index'); var subsection = $currentElement.attr('data-subsection'); // get section title from the h2 var section = $currentElement.parent().siblings('h2.section-title').attr('data-section'); var searchString = Drupal.settings.bfiSearchString; //get the result container to append results to var $contentElement = $currentElement.parent().children('.bfi-search-content'); //get the currently viewed element to update number of results shown var $currentlyViewingElement = $currentElement.siblings('.bfi-more-search-results-info').children('.currently-viewing'); //show the loader $currentElement.addClass('bfi-search-more-loader'); // console.log(Drupal.settings.basePath + 'search-bfi-callback/' + startIndex + '/' + searchString + '/' + section + '/' + subsection) //get some more results from solr $.ajax({ beforeSend: function() { ajaxingSearch = true; //to make sure a click can't happen whilst ajaxing }, complete: function() { //hide the loader $currentElement.removeClass('bfi-search-more-loader'); //allow clicking again now ajax is complete ajaxingSearch = false; }, url: Drupal.settings.basePath + 'search-bfi-callback/' + startIndex + '/' + searchString + '/' + section + '/' + subsection, success: function(data) { if (data.output) { start = parseInt(data[section][subsection].start); numFound = parseInt(data[section][subsection].num_found); //append results to the results container $contentElement.append(data.output); //add background color to the new group of results and then fade out and remove the active class $('.bfi-search-result-group.active').css('background-color', '#FFDEAD').animate({"backgroundColor":"transparent"}, 2000).removeClass('active'); //hide the more action if no more results to fetch if (start == numFound) { $currentElement.hide(); } else { //increment the next start index for more results $currentElement.attr('data-start-index', start); } //update the label to show number of currently viewing $currentlyViewingElement.text(start); } } }); } }); } }; /** * behaviour to calculate the total number of search results * only runs after 'What's On' ajax request is finished */ Drupal.behaviors.get_total_search_results = { attach: function (context, settings) { $(document).ajaxStop(function () { var total_results = 0; $( ".number-of-results" ).each(function() { total_results += parseInt($(this).text()); }); if (total_results == 0) { total_results = 'no'; } $('.search_results_count').text(total_results); }); } }; /** * Behaviour that makes an Ajax request to a function that retrieves information * from the What's on website * @type {Object} */ Drupal.behaviors.bfi_whatson_search = { attach: function (context, settings) { // get the current path to only look for what's on results on search results page var path = window.location.pathname; var n = path.search("search-bfi"); // means that we're on the search results page if(n != -1){ $.ajax({ complete: function() { $('#bfi-whatson-progress').hide(); }, //encodeURIComponent() url: Drupal.settings.basePath + 'bfi-whatson-search/' + Drupal.settings.bfiSearchString, success: function(data) { if (data) { $('.bfi-search-wrapper').prepend(data); //set the flag in the client to say, hey I've got some results Drupal.settings.bfiSearchResultsFlag = true; //show the block title, its hidden whilst searching for content $('.bfi-whatson-title').show(); } else { //remove the block if no results, block had to be shown in the first place to show the spinner $('#block-bfi-whatson-search-bfi-whatson-search').remove(); } } }); } } }; // Google custom search. Drupal.behaviors.bfi_google_custom_search = { attach: function (context, settings) { Drupal.settings.bfiGoogleCustomSearchDone = false; // If behaviors is called again we dont want to execute this code (usually add .once() for this but we havent got an element to process in the first place) var cxList = [ { cx: '015290309371669849591:zjk-6n_joz4', // cx from the setup in google custom search. id: 'bfi-shop', section: 'BFI Shop', title: 'BFI Shop' }, { cx: '015290309371669849591:juk8lqay5ku', // cx from the setup in google custom search. id: 'bfi-player', section: 'BFI Player', title: 'BFI Player' } ]; var apiKey = "AIzaSyBihkG-cTiy0WEAKq-U8_U-4SrzVF-arHQ"; // api key from the setup in google console. var googleapiCustomSearch = "https://www.googleapis.com/customsearch/v1?callback=?"; if (!Drupal.settings.bfiGoogleCustomSearchDone) { $.each(cxList, function(i, cxListItem) { $.getJSON(googleapiCustomSearch, { key: apiKey, cx: cxListItem.cx, q: Drupal.settings.bfiSearchString, num: 5 }).done(function(data) { if (typeof data.items !== 'undefined') { $('.bfi-search-wrapper').prepend(Drupal.theme('bfiFrontendResultsWrapper', data, cxListItem)); } }); }); Drupal.settings.bfiGoogleCustomSearchDone = true; } } } //THEME results wrapper for results presented via frontend calls. Drupal.theme.prototype.bfiFrontendResultsWrapper = function(data, cxListItem) { var themedResults = ''; return themedResults; } //THEME results item for results presented via frontend calls. Drupal.theme.prototype.bfiFrontendResultsItem = function(item) { var themedItem = ''; if (typeof item.pagemap.cse_thumbnail !== 'undefined') { themedItem += '
    '; } themedItem += '

    ' + item.title + '

    '; themedItem += '

    ' + item.snippet + '

    ' + item.displayLink + '

    '; if (typeof item.pagemap.cse_thumbnail !== 'undefined') { themedItem += '
    '; } themedItem += '
    '; return themedItem; } })(jQuery); ; (function ($) { Drupal.behaviors._bfi_kaltura_responsive = { attach: function (context, settings) { $('iframe.kaltura-player').parent().addClass('bfi-video-embed-container'); } }; })(jQuery); ; (function ($) { Drupal.behaviors._bfi_youtube_vimeo_responsive = { attach: function (context, settings) { $('iframe.youtube-vimeo-player').parent().addClass('bfi-video-embed-container'); } }; })(jQuery); ;